package com.tky.questions.ui.acitivity;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.widget.RadioGroup;
import android.widget.TabHost;

import com.tky.questions.R;
import com.tky.questions.ui.fragment.CompleteFragment;
import com.tky.questions.ui.fragment.LateFragment;
import com.tky.questions.ui.fragment.TodoFragment;

/**
 * Created by WX on 2016/4/11.
 */
public class HomePageAcitivity extends FragmentActivity {

    private FragmentTabHost mTabHost;
    private RadioGroup mTabRg;

    private final Class[] fragments = {LateFragment.class,
            TodoFragment.class, CompleteFragment.class};

    @Override
    protected final void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_homepage);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// 禁止旋转

        initView();

    }

    private void initView() {
        mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
        // 得到fragment个数
        int count = fragments.length;
        for (int i = 0; i < count; i++) {
            // 为每一个按钮设置图标和文字
            TabHost.TabSpec tabSpec = mTabHost.newTabSpec(i + "").setIndicator(i + "");
            mTabHost.addTab(tabSpec, fragments[i], null);
        }

        mTabRg = (RadioGroup) findViewById(R.id.tab_rg_menu);
        mTabRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.tab_rb_1:
                        mTabHost.setCurrentTab(0);
                        break;
                    case R.id.tab_rb_2:
                        mTabHost.setCurrentTab(1);
                        break;
                    case R.id.tab_rb_3:
                        mTabHost.setCurrentTab(2);
                        break;
                    default:
                        break;
                }
            }
        });
        mTabHost.setCurrentTab(0);
    }

}